package com.lphj.datainterface.controller;

import com.google.gson.Gson;
import com.lphj.datainterface.entity.TGoods;
import com.lphj.datainterface.service.TGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class TGoodsController {

    @Autowired
    TGoodsService tGoodsService;

    @RequestMapping("getTGoodsInfo")
    String getTGoodsInfo(String name,String value) {
        TGoods tGoods = null;
        Gson gson = new Gson();
        if(name.equals("goodsName")) {
            tGoods = tGoodsService.getTGoodsByGoodsName(value);
            if(tGoods != null) {
                return gson.toJson(tGoods);
            }
        }
        return "null";
    }
    @RequestMapping("changeGoodsInfo")
    String changeGoodsInfo(String sGoodsDesc ,String sGoodsNO2,String sGoodsNO3) {
        Map<String,Object> data = new HashMap<>();
        Gson gson = new Gson();
        if(tGoodsService.unifiedTGoods(sGoodsNO2,sGoodsDesc,sGoodsNO3) > 0) {
            data.put("success","修改成功");
        } else {
            data.put("success","修改失败");
        }
        return gson.toJson(data);
    }
}
